// react + ts
// useState泛型参数

import { useState } from "react"

type User = {
  name: string
  age: number
}

function App02() {
  // 限制初始值类型
  const [user, setUser] = useState<User>({
    name: 'Jack',
    age: 18
  })

  const [user2, setUser2] = useState<User>(() => {
    return {
      name: 'Jack',
      age: 18
    }
  })

  // 
  const changeUser = () => {
    setUser({
      name: 'Jack',
      age: 18
    })
  }
  const changeUser2 = () => {
    setUser(() => {
      return {
        name: 'Jack',
        age: 18
      }
    })
  }

  return (
    <>
      this is app {user.name}
    </>
  )
}

export default App02
